package com.ftg.learn.chapter12;

import java.util.*;

/**
 * fs
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/2/15 上午9:48
 */
public class Solution {
    public static Map<Integer, String> threeSum(int[] nums) {
        Map<Integer, String> map = new HashMap<>();
        List<List<Integer>> l = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1, k = j + 1; k < nums.length; j++, k++) {
                if (nums[i] + nums[j] + nums[k] == 0) {
                    map.put(i + j + k, "[" + i + "," + j + "," + k + "]");
//                    boolean t = true;
//                    for (String s : map.keySet()) {
//                        s.split(",");
//                        int sum =
//                        if ( == (i + j + k)) {
//                            t = false;
//                            break;
//                        }
//                    }
//                    String key = "".concat(i + ",").concat(j + ",").concat(k + "");
//                    if (t) map.put(key, "[" + i + "," + j + "," + k + "]");
                }
            }
        }
        return map;
    }

    public static List<List<Integer>> threeSum1(int[] nums) {
        List<List<Integer>> l = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                for (int k = j + 1; k < nums.length; k++) {
                    if (nums[i] + nums[j] + nums[k] == 0) {
                        List<Integer> list1 = Arrays.asList(nums[i], nums[j], nums[k]);
                        Collections.sort(list1);
                        if (!l.contains(list1)) {
                            l.add(list1);
                        }
                    }
                }
            }
        }
        return l;
    }

    public static void main(String[] args) {
        System.out.println(threeSum1(new int[]{-2, 0, 1, 1, 2}));
    }
}